﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using NETL.Engine.Context;
using NETL.Engine.Util;

namespace NETL.Engine.Source
{
	public class SourceFactory : ISourceFactory
	{

		public static ISourceFactory Instance()
		{
			return new SourceFactory();
		}

		#region ISourceFactory Members

		public IMessageSource BuildSource(NETL.Data.Config.SourceData data)
		{
			IMessageSource s = ClassFactory.Instance().BuildClass(data.Class) as IMessageSource;
			s.Name = data.Name;
			
			foreach (XElement e in data.Data.Elements())
			{
				ReflectionUtil.SetProperty(s, e);
			}

			return s;
		}

		#endregion
	}
}
